import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class CardGame {

    // 牌值映射表
    private static final Map<Character, Integer> cardValueMap = new HashMap<>();
    static {
        cardValueMap.put('A', 14);
        cardValueMap.put('K', 13);
        cardValueMap.put('Q', 12);
        cardValueMap.put('J', 11);
        cardValueMap.put('T', 10);
        cardValueMap.put('9', 9);
        cardValueMap.put('8', 8);
        cardValueMap.put('7', 7);
        cardValueMap.put('6', 6);
        cardValueMap.put('5', 5);
        cardValueMap.put('4', 4);
        cardValueMap.put('3', 3);
        cardValueMap.put('2', 15);  // 2 是特殊牌
    }

    public int compareCards(String firstCards, String secondCards) {
        // 确定牌的长度来判断牌型
        int len1 = firstCards.length();
        int len2 = secondCards.length();

        // 单牌比较
        if (len1 == 1 && len2 == 1) {
            return compareSingle(firstCards.charAt(0), secondCards.charAt(0));
        }

        // 对子比较
        if (len1 == 2 && len2 == 2 && firstCards.charAt(0) == firstCards.charAt(1)
                && secondCards.charAt(0) == secondCards.charAt(1)) {
            return comparePair(firstCards.charAt(0), secondCards.charAt(0));
        }

        // 炸弹比较
        if (len1 == 3 && len2 == 3 && firstCards.charAt(0) == firstCards.charAt(1)
                && firstCards.charAt(1) == firstCards.charAt(2)
                && secondCards.charAt(0) == secondCards.charAt(1)
                && secondCards.charAt(1) == secondCards.charAt(2)) {
            return compareBomb(firstCards.charAt(0), secondCards.charAt(0));
        }

        // 无法比较的情况
        return 2;
    }

    // 单牌比较
    private int compareSingle(char firstCard, char secondCard) {
        int value1 = cardValueMap.get(firstCard);
        int value2 = cardValueMap.get(secondCard);

        if (firstCard == '2' || secondCard == '2') {
            return Integer.compare(value1, value2);
        }

        if (Math.abs(value1 - value2) == 1) {
            return Integer.compare(value1, value2);
        }

        return 2;
    }

    // 对子比较
    private int comparePair(char firstCard, char secondCard) {
        int value1 = cardValueMap.get(firstCard);
        int value2 = cardValueMap.get(secondCard);

        if (firstCard == '2' || secondCard == '2') {
            return Integer.compare(value1, value2);
        }

        if (Math.abs(value1 - value2) == 1) {
            return Integer.compare(value1, value2);
        }

        return 2;
    }

    // 炸弹比较
    private int compareBomb(char firstCard, char secondCard) {
        int value1 = cardValueMap.get(firstCard);
        int value2 = cardValueMap.get(secondCard);

        return Integer.compare(value1, value2);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取输入
        String input = scanner.nextLine();
        String[] cards = input.split(" ");

        if (cards.length != 2) {
            System.out.println("err");
            return;
        }

        String firstCards = cards[0];
        String secondCards = cards[1];

        CardGame game = new CardGame();
        int result = game.compareCards(firstCards, secondCards);

        // 输出结果
        switch (result) {
            case 1:
                System.out.println("1");
                break;
            case -1:
                System.out.println("-1");
                break;
            case 0:
                System.out.println("0");
                break;
            case 2:
                System.out.println("2");
                break;
        }

        scanner.close();
    }
}
